<?php
/*
 * Copyright 2009 Eat Local Food, LLC
 * Copyright (c) 2008 osCommerce (this file was written after
 * code review of osCommerce).
 *
 * This file is part of gwtCommerce.
 *
 * gwtCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * gwtCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gwtCommerce.  If not, see <http://www.gnu.org/licenses/>.
 */

require_once('includes/functions/module_functions.php');
class moneyorder {

	// class constructor
	function moneyorder()
	{
		$this->module_key = 'MODULE_PAYMENT_MONEYORDER';
		$this->code = 'moneyorder';
		$this->enabled = ((MODULE_PAYMENT_MONEYORDER_STATUS == 'true') ? true : false);
		$this->sort_order = MODULE_PAYMENT_MONEYORDER_SORT_ORDER;
		$this->status_id = MODULE_PAYMENT_MONEYORDER_ORDER_STATUS_ID;
		$this->email_footer = MODULE_PAYMENT_MONEYORDER_TEXT_EMAIL_FOOTER;
	}

	// class methods

	function confirm_zone($params, &$checkout_component)
	{
		return check_zone(MODULE_PAYMENT_MONEYORDER_ZONE, $checkout_component->billTo['country_id'], $checkout_component->billTo['zone_id']);
	}

	function setup(&$params, &$checkout_component)
	{
		$setup['code'] = $this->code;
		$setup['payment_method'] = 'moneyorder';
		$setup['sort_order'] = $this->sort_order;

		return $setup;
	}

	function process(&$params, &$checkout_component)
	{
		$params['payment_method'] = 'moneyorder';
	}

	function check() {
		if (!isset($this->_check)) {
			$this->_check = check_module($this->module_key);
		}
		return $this->_check;
	}

	function install() {
		run_sql("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, configuration_values, date_added) values ('Enable Check/Money Order Module', 'MODULE_PAYMENT_MONEYORDER_STATUS', 'true', 'Do you want to accept Check/Money Order payments?', '6', '1','true, false', now());");
		run_sql("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_MONEYORDER_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
		run_sql("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, configuration_values, date_added) values ('Payment Zone', 'MODULE_PAYMENT_MONEYORDER_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'geo_zone_list()', now())");
		run_sql("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, configuration_values, date_added) values ('Set Order Status', 'MODULE_PAYMENT_MONEYORDER_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'order_status_list()', now())");
		run_sql("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Make Payable to:', 'MODULE_PAYMENT_MONEYORDER_PAYTO', 'gwtCommerce', 'Who should payments be made payable to?', '6', '1', now());");
	}

	function remove() {
		remove_module($this->module_key);
	}
}
?>
